package com.bjshiwei.zhengu.adapter;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

/**
 * 作者：Administrator on 2017/2/9 0009 18:21
 * 邮箱：sanjins@126.com
 */


public class MyViewpagerAdapter extends PagerAdapter{

    private List<View> mViews;

    @Override
    public int getCount() {
        return mViews==null?0:mViews.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view==object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        container.addView(mViews.get(position % mViews.size()));
        return mViews.get(position % mViews.size());
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        // super.destroyItem(container, position, object);
        container.removeView(mViews.get(position % mViews.size()));
    }

    public void clear(){
        mViews.clear();
        notifyDataSetChanged();
    }


    public void addAll(List<View> views){
        mViews.addAll(views);
        notifyDataSetChanged();
    }

}
